package ru.acme.lab09.domain.account;

public class CheckingAccount extends AbstractAccount {

	private int overdraft;
	
	public CheckingAccount(int balance, int overdraft) {
		super(balance);
		this.overdraft = overdraft;
	}

	public boolean withdraw(int amount) {
		if (super.getBalance() + overdraft >= amount) {
			if (super.getBalance() >= amount) {
				super.withdraw(amount);
			} else {
				amount -= super.getBalance();
				super.withdraw(super.getBalance());
				overdraft -= amount;
			}
			return true;
		}
		return false;
	}

	public int maximumAmountToWithdraw() {
		return overdraft + super.maximumAmountToWithdraw();
	}

}
